{% extends "zato/index.html" %}

{% block html_title %}SFTP outconns{% endblock %}

{% block "extra_css" %}
    <link rel="stylesheet" type="text/css" href="/static/css/jquery.alerts.css">
{% endblock %}

{% block "extra_js" %}

    {% comment %} jQuery {% endcomment %}
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.tablesorter.min.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.cookie.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.alerts.min.js"></script>

    {% comment %} Common JS {% endcomment %}
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/common.js"></script>

    {% comment %} SFTP {% endcomment %}
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/outgoing/sftp.js"></script>

    <script nonce="{{ CSP_NONCE }}">
    $.fn.zato.data_table.get_columns = function() {
        return [
            '_numbering',
            '_selection',

            {% comment %} 1 {% endcomment %}
            'name',
            '_is_active',
            '_host',

            {% comment %} 2 {% endcomment %}
            '_port',
            '_username',
            '_identity_file',

            {% comment %} 3 {% endcomment %}
            '_default_directory',
            '_command_shell',
            '_edit',

            {% comment %} 4 {% endcomment %}
            '_delete',
            '_ping',
            'id',

            {% comment %} 5 {% endcomment %}
            'is_active',
            'log_level',
            'host',

            {% comment %} 6 {% endcomment %}
            'port',
            'username',
            'identity_file',

            {% comment %} 7 {% endcomment %}
            'ssh_config_file',
            'buffer_size',
            'is_compression_enabled',

            {% comment %} 8 {% endcomment %}
            'force_ip_type',
            'should_flush',
            'should_preserve_meta',

            {% comment %} 9 {% endcomment %}
            'ssh_options',
            'sftp_command',
            'ping_command',

            {% comment %} 10 {% endcomment %}
            'bandwidth_limit',
            'default_directory',
        ]
    }
    </script>


{% endblock %}

{% block "content" %}
<h2 class="zato">Outgoing SFTP connections</h2>

{% if not zato_clusters %}
    {% include "zato/no-clusters.html" %}
{% else %}

    <div id="user-message-div" style='display:none'><pre id="user-message" class="user-message"></pre></div>

{% if is_disabled %}
    {% include "zato/disabled-windows.html" %}
{% else %}

{% with has_generic="1" generic_type="outconn-sftp" %}
    {% include "zato/search-form.html" with page_prompt="Show connections" %}
{% endwith %}


    {% if cluster_id %}
        <div class='page_prompt' style="clear:left">
            <a href="javascript:$.fn.zato.outgoing.sftp.create()">Create a new outgoing SFTP connection</a>
        </div>


        <div id="markup">
            <table id="data-table">
                <thead>
                    <tr class='ignore'>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>

                        {% comment %} 1 {% endcomment %}
                        <th><a href="#">Name</a></th>
                        <th><a href="#">Active</a></th>
                        <th><a href="#">Host</a></th>

                        {% comment %} 2 {% endcomment %}
                        <th><a href="#">Port</a></th>
                        <th><a href="#">Username</a></th>
                        <th><a href="#">Identity file</a></th>

                        {% comment %} 3 {% endcomment %}
                        <th><a href="#">Default dir.</a></th>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>

                        {% comment %} 4 {% endcomment %}
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>

                        {% comment %} 5 {% endcomment %}
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>

                        {% comment %} 6 {% endcomment %}
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>

                        {% comment %} 7 {% endcomment %}
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>

                        {% comment %} 8 {% endcomment %}
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>

                        {% comment %} 9 {% endcomment %}
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>

                        {% comment %} 10 {% endcomment %}
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>

                </thead>

                <tbody>
                {% if items %}
                {% for item in items %}
                    <tr class="{% cycle 'odd' 'even' %}" id='tr_{{ item.id }}'>
                        <td class='numbering'>&nbsp;</td>
                        <td class="impexp"><input type="checkbox" /></td>

                        {% comment %} 1 {% endcomment %}
                        <td>{{ item.name }}</td>
                        <td>{{ item.is_active|yesno:'Yes,No' }}</td>
                        <td>{{ item.host|default:'<span class="form_hint">---</span>' }}</td>

                        {% comment %} 2 {% endcomment %}
                        <td>{{ item.port|default:'<span class="form_hint">---</span>' }}</td>
                        <td>{{ item.username|default:'<span class="form_hint">---</span>' }}</td>
                        <td>{{ item.identity_file|default:'<span class="form_hint">---</span>' }}</td>

                        {% comment %} 3 {% endcomment %}
                        <td>{{ item.default_directory|default:'<span class="form_hint">---</span>' }}</td>
                        <td><a href="{% url "out-sftp-command-shell" item.id cluster_id item.name|slugify %}?name={{ item.name|urlencode:"" }}">Command shell</a></td>
                        <td><a href="javascript:$.fn.zato.outgoing.sftp.edit('{{ item.id }}')">Edit</a></td>

                        {% comment %} 4 {% endcomment %}
                        <td><a href="javascript:$.fn.zato.outgoing.sftp.delete_('{{ item.id }}')">Delete</a></td>
                        <td><a href="javascript:$.fn.zato.data_table.ping('{{ item.id }}')">Ping</a></td>
                        <td class='ignore item_id_{{ item.id }}'>{{ item.id }}</td>

                        {% comment %} 5 {% endcomment %}
                        <td class='ignore'>{{ item.is_active }}</td>
                        <td class='ignore'>{{ item.log_level }}</td>
                        <td class='ignore'>{{ item.host }}</td>

                        {% comment %} 6 {% endcomment %}
                        <td class='ignore'>{{ item.port|default:'' }}</td>
                        <td class='ignore'>{{ item.username|default:'' }}</td>
                        <td class='ignore'>{{ item.identity_file }}</td>

                        {% comment %} 7 {% endcomment %}
                        <td class='ignore'>{{ item.ssh_config_file }}</td>
                        <td class='ignore'>{{ item.buffer_size }}</td>
                        <td class='ignore'>{{ item.is_compression_enabled }}</td>

                        {% comment %} 8 {% endcomment %}
                        <td class='ignore'>{{ item.force_ip_type }}</td>
                        <td class='ignore'>{{ item.should_flush }}</td>
                        <td class='ignore'>{{ item.should_preserve_meta }}</td>

                        {% comment %} 9 {% endcomment %}
                        <td class='ignore'>{{ item.ssh_options }}</td>
                        <td class='ignore'>{{ item.sftp_command }}</td>
                        <td class='ignore'>{{ item.ping_command }}</td>

                        {% comment %} 10 {% endcomment %}
                        <td class='ignore'>{{ item.bandwidth_limit }}</td>
                        <td class='ignore'>{{ item.default_directory }}</td>

                    </tr>
                {% endfor %}
                {% else %}
                    <tr class='ignore'>
                        <td colspan='31'>No results</td>
                    </tr>
                {% endif %}

                </tbody>
            </table>
        </div>

{% include "zato/paginate/action-panel.html" %}

        <div id="create-div" class='data-popup ignore'>
            <div class="bd">
                <form novalidate action="{% url "out-sftp-create" %}" method="post" id="create-form">
                    <table class="form-data">

                        <tr>
                            <td style="vertical-align:middle;width:10%">Name</td>
                            <td>{{ create_form.name }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Options</td>
                            <td>

                                <label>
                                Active
                                {{ create_form.is_active }}
                                </label>

                                |

                                <label>
                                Preserve meta
                                {{ create_form.should_preserve_meta }}
                                </label>

                                |

                                <label>
                                Flush immd.
                                {{ create_form.should_flush }}
                                </label>

                                |

                                <label>
                                Log level <span class="form_hint">(0=min)</span>
                                {{ create_form.log_level }}
                                </label>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle"></td>
                            <td>

                                <label>
                                Buffer size
                                {{ create_form.buffer_size }}
                                </label>

                                |

                                <label>
                                Bandw. limit <span class="form_hint">(in MB)</span>
                                {{ create_form.bandwidth_limit }}
                                </label>

                                |

                                <label>
                                IP type
                                {{ create_form.force_ip_type }}
                                </label>

                            </td>
                        </tr>


                        <tr>
                            <td style="vertical-align:middle">
                                <label for="id_host">Host</label>
                            </td>
                            <td>
                                {{ create_form.host }}

                                |

                                <label>
                                Port
                                {{ create_form.port }}
                                </label>

                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">
                                <label for="id_username">Username</label>
                            </td>
                            <td>
                                {{ create_form.username }}
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">
                                <label for="id_sftp_command">SFTP command</label>
                            </td>
                            <td>
                                {{ create_form.sftp_command }}

                                |

                                <label>
                                Ping command
                                {{ create_form.ping_command }}
                                </label>

                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">
                                <label for="id_identity_file">Ident. file</label>
                            </td>
                            <td>
                                {{ create_form.identity_file }}
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">
                                <label for="id_ssh_config_file">Conf. file</label>
                            </td>
                            <td>
                                {{ create_form.ssh_config_file }}
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">
                                <label for="id_default_directory">Default directory</label>
                            </td>
                            <td>
                                {{ create_form.default_directory }}
                            </td>
                        </tr>

                        <tr>
                            <td colspan="2">
                            <label for="id_ssh_options">SSH options</label>
                            <br/>
                            {{ create_form.ssh_options }}
                            </td>
                        </tr>

                        <tr>
                            <td colspan="2" style="text-align:right">
                                <input type="submit" value="OK" />
                                <button type='button' onclick='javascript:$.fn.zato.data_table.close(this)'>Cancel</button>
                            </td>
                        </tr>

                    </table>
                    <input type="hidden" id="cluster_id" name="cluster_id" value="{{ cluster_id }}" />
                </form>
            </div>
        </div>

        <div id="edit-div" class='data-popup ignore'>
            <div class="bd">
                <form novalidate action="{% url "out-sftp-edit" %}" method="post" id="edit-form">
                    <table class="form-data">

                        <tr>
                            <td style="vertical-align:middle;width:10%">Name</td>
                            <td>{{ edit_form.name }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Options</td>
                            <td>

                                <label>
                                Active
                                {{ edit_form.is_active }}
                                </label>

                                |

                                <label>
                                Preserve meta
                                {{ edit_form.should_preserve_meta }}
                                </label>

                                |

                                <label>
                                Flush immd.
                                {{ edit_form.should_flush }}
                                </label>

                                |

                                <label>
                                Log level <span class="form_hint">(0=min)</span>
                                {{ edit_form.log_level }}
                                </label>
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle"></td>
                            <td>

                                <label>
                                Buffer size
                                {{ edit_form.buffer_size }}
                                </label>

                                |

                                <label>
                                Bandw. limit <span class="form_hint">(in MB)</span>
                                {{ edit_form.bandwidth_limit }}
                                </label>

                                |

                                <label>
                                IP type
                                {{ edit_form.force_ip_type }}
                                </label>

                            </td>
                        </tr>


                        <tr>
                            <td style="vertical-align:middle">
                                <label for="id_edit-host">Host</label>
                            </td>
                            <td>
                                {{ edit_form.host }}

                                |

                                <label>
                                Port
                                {{ edit_form.port }}
                                </label>

                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">
                                <label for="id_edit-username">Username</label>
                            </td>
                            <td>
                                {{ edit_form.username }}
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">
                                <label for="id_edit-sftp_command">SFTP command</label>
                            </td>
                            <td>
                                {{ edit_form.sftp_command }}

                                |

                                <label>
                                Ping command
                                {{ edit_form.ping_command }}
                                </label>

                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">
                                <label for="id_edit-identity_file">Ident. file</label>
                            </td>
                            <td>
                                {{ edit_form.identity_file }}
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">
                                <label for="id_edit-ssh_config_file">Conf. file</label>
                            </td>
                            <td>
                                {{ edit_form.ssh_config_file }}
                            </td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">
                                <label for="id_edit-default_directory">Default directory</label>
                            </td>
                            <td>
                                {{ edit_form.default_directory }}
                            </td>
                        </tr>

                        <tr>
                            <td colspan="2">
                            <label for="id_edit-ssh_options">SSH options</label>
                            <br/>
                            {{ edit_form.ssh_options }}
                            </td>
                        </tr>

                        <tr>
                            <td colspan="2" style="text-align:right">
                                <input type="submit" value="OK" />
                                <button type='button' onclick='javascript:$.fn.zato.data_table.close(this)'>Cancel</button>
                            </td>
                        </tr>

                    </table>
                    <input type="hidden" id="id_edit-cluster_id" name="cluster_id" value="{{ cluster_id }}" />
                    <input type="hidden" id="id_edit-id" name="id" />
                </form>
            </div>
        </div>

    {% endif %}

{% endif %}{% comment %}is_disabled{% endcomment %}

{% endif %}{% comment %}not zato_clusters{% endcomment %}

{% endblock %}
